<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>首页</title>
<style type="text/css">
body {
	background-image: url(../static/img/shot_5_cat.png);
	background-repeat: repeat;
	border: 0px dotted #F20C0F;
	text-align: center;
}
#form1 p label {
	margin-right: 10px;
	right: auto;
	width: 200px;
	height: 200px;
	color: #0EBD38;
	font-size: x-large;
}
#form1 p #submit {
	margin-right: 10px;
	margin-left: 10px;
	width: 100px;
	height: 35px;
}
#form1 p #submit2 {
	width: 100px;
	height: 35px;
}
#form1 p #textfield {
	width: 200px;
	height: 40px;
}
#form1 p #password {
	width: 200px;
	height: 40px;
}
#form1 p #Name {
	width: 200px;
	height: 40px;
}

@media screen {
}
</style>
<!-- <link href="../static/css/Main.css" rel="stylesheet" type="text/css"> -->
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
</script> 
<script>
$(document).ready(function(){
	$("#register").click(function(){
		var Name = $('#Name').val();
		var password = $('#password').val();
		var data = JSON.stringify({
				"Name": Name,
				"password": password,				
		  });
		if (Name == "") 
    	{
			alert("请填写用户名！");
			
			return ;
    	}
		if (password.length < 6) 
    	{
			alert("密码最少6位");
			
			return ;
    	}
		$.ajax({
			url:"/Register",
			async: true,
			data:data,
			type: "post",
			dataType: "json",
			headers: {
				"Content-Type": "application/json"
			},
			success:function(result){
				console.log("success:" + result);
				if(result.code == 200){
					alert("注册成功");	
				}
				else{
					alert("注册失败");	
				}
			},
			error: function () {
                alert("服务器发生了错误")
            }
		});
	});
	$("#login").click(function(){
		var Name = $('#Name').val();
		var password = $('#password').val();
		var data = JSON.stringify({
				"Name": Name,
				"password": password,				
		  });
		if (Name == "") 
    	{
			alert("请填写用户名！");
			
			return ;
    	}
		if (password.length < 6) 
    	{
			alert("密码最少6位");
			
			return ;
    	}
		$.ajax({
			url:"/Login",
			async: true,
			data:data,
			type: "post",
			dataType: "json",
			headers: {
				"Content-Type": "application/json"
			},
			success:function(result){
				console.log("success:" + result);
				if(result.code == 200){
					var msg = confirm("登录成功");
					if (msg) {
						window.location.href = "/LoginConfirm";
					}
				}
				else{
					alert("账号密码错误");	
				}
			},
			error: function () {
                alert("服务器发生了错误")
            }
		});
	});
	
	$("#form1").submit(function(){
		return false;
	})
});
	
function SendForm () 
{
    if(CheckPost()) 
    {
        document.addForm.submit();
    }
}
  
function CheckPost () 
{
    if (addForm.user.value == "") 
    {
        alert("请填写用户名！");
        addForm.username.focus();
        return false;
    }
    if (addForm.title.value.length < 5) 
    {
        alert("标题不能少于5个字符！");
        addForm.title.focus();
        return false;
    }
    return false;
}	
</script>
</head>

<body>
<p><a href="https://www.bilibili.com/video/BV1NE411C7bR/?p=5&spm_id_from=pageDriver&vd_source=0ee25921064c65405a9e5c82331fbe58" target="_blank">转至哔哩</a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<form id="form1" name="form1" method="post">
  <p>
    <label for="Name"> 账号:</label>
    <input name="Name" type="text" required="required" id="Name" placeholder="输入账号">
  </p>
  <p>
    <label for="password">密码:</label>
    <input name="password" type="password" required="required" id="password" placeholder="输入密码">
  </p>
  <p>
    <input name="submit" type="submit" id="register" formaction="/Register" formmethod="POST" value="注册">
    <input name="submit2" type="submit" id="login" formaction="/Login" formmethod="POST" value="登录">
  </p>
</form>
</body>
</html>
